package com.zzsy.carosshopprojects.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.king.base.adapter.ViewHolderRecyclerAdapter;
import com.king.base.adapter.holder.ViewHolder;
import com.yatoooon.screenadaptation.ScreenAdapterTools;
import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.bean.ReghterOrderBean;
import com.zzsy.carosshopprojects.util.ConverterHelper;
import com.zzsy.carosshopprojects.util.FormatTimeUtil;
import com.zzsy.carosshopprojects.util.StringUtils;

import java.math.BigDecimal;
import java.util.List;

public class OrderReghterAdapter extends ViewHolderRecyclerAdapter<ReghterOrderBean.OrdersBean> {


    public OrderReghterAdapter(Context context, List<ReghterOrderBean.OrdersBean> listData, int layoutId) {
        super(context, listData, layoutId);
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.adapter_orderreghter, null);
        ScreenAdapterTools.getInstance().loadView(view);
        return view;
    }

    @Override
    public void bindViewDatas(ViewHolder helper,ReghterOrderBean.OrdersBean ordersBean, int positions) {
        helper.setText(R.id.tv_order_nums, ordersBean.getRechargeNumber());
        String source = ordersBean.getSource();
        String amount = ordersBean.getAmount();
        if (!StringUtils.isEmpty(amount)) {
            double reghterAmounts = ConverterHelper.toBigDecimal(amount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            helper.setText(R.id.tv_rehgter_amount, "￥" + reghterAmounts);
        }
        String orderCreateTime = ordersBean.getOrderCreateTime();
        if (!StringUtils.isEmpty(orderCreateTime)) {
            helper.setText(R.id.tv_order_time, FormatTimeUtil.formatTimeStamp2DateStr(String.valueOf(Long.parseLong(orderCreateTime) / 1000), "yyyy-MM-dd HH:mm:ss"));
        }
        if (StringUtils.isEmpty(source)) {
            source = "未知来源";
        }
        if ("1".equals(source)) {
            helper.setText(R.id.tv_rehgter_source, "小程序");
        } else if ("3".equals(source)) {
            helper.setText(R.id.tv_rehgter_source, "手持终端");
        } else {
            helper.setText(R.id.tv_rehgter_source, "未知来源");
        }

    }

}
